<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Db;

class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
        return $this->view->fetch();
    }
    public function tbaddressp2s()
    {
		$ctime=time();
		$paotui=Db::name('paotui_user_address')->column('user_id');
		$nopt=Db::name('shopro_user_address')->where('user_id','not in',$paotui)->select();
		p($nopt);
		
		// foreach($nopt as $k=>$v){
			// $inarr=[
				// 'shopro_address_id'=>$v['id'],
				// 'user_id'=>$v['user_id'],
				// 'is_default'=>$v['is_default'],
				// 'name'=>$v['consignee'],
				// 'mobile'=>$v['mobile'], 
				// 'province'=>$v['province_name'],
				// 'city'=>$v['city_name'],
				// 'district'=>$v['district_name'],
				// 'poi'=>$v['poi'],
				// 'lng'=>$v['lng'],
				// 'lat'=>$v['lat'],
				// 'address'=>$v['address'],
				// 'province_id'=>$v['province_id'],
				// 'city_id'=>$v['city_id'],
				// 'district_id'=>$v['district_id'],
				// 'num'=>0,
				// 'createtime'=>$ctime,
				// 'updatetime'=>$ctime,
			// ];
			// Db::name('paotui_user_address')->insert($inarr);
		// }
		
		
		// $shopro=Db::name('shopro_user_address')->column('user_id');
		// $nosp=Db::name('paotui_user_address')->where('user_id','not in',$shopro)->select();
		// p($nosp);
		
		// foreach($nosp as $k=>$v){
			// $inarr=[
				// 'user_id'=>$v['user_id'],
				// 'is_default'=>1,
				// 'consignee'=>$v['name'],
				// 'mobile'=>$v['mobile'], 
				// 'province_name'=>$v['province'],
				// 'city_name'=>$v['city'],
				// 'district_name'=>$v['district'],
				// 'poi'=>$v['poi'],
				// 'lng'=>$v['lng'],
				// 'lat'=>$v['lat'],
				// 'address'=>$v['address'],
				// 'province_id'=>$v['province_id'],
				// 'city_id'=>$v['city_id'],
				// 'district_id'=>$v['district_id'],
				// 'createtime'=>$ctime,
				// 'updatetime'=>$ctime,
			// ];
			// $lid=Db::name('shopro_user_address')->insertGetId($inarr);
			// if($lid)Db::name('paotui_user_address')->update(['shopro_address_id'=>$lid,'id'=>$v['id']]);
		// }
		
		echo 'complete!';
    }

	//定时更新状态/是否删除 5-10秒一次
	public function intervalOrderMerge(){
		Db::name('order_merge')->execute("update pt_order_merge a set status=(select status from pt_paotui_post pp where pp.id=a.order_ids) where (select status from pt_paotui_post pp where pp.id=a.order_ids)<>status and tb_name='paotui_post'");
		Db::name('order_merge')->execute("update pt_order_merge a set status=(select status from pt_shopro_order pp where pp.id=a.order_ids) where (select status from pt_shopro_order pp where pp.id=a.order_ids)<>status and tb_name='shopro_order'");
		Db::name('order_merge')->execute("update pt_order_merge a set deletetime=(select deletetime from pt_paotui_post pp where pp.id=a.order_ids) where (select deletetime from pt_paotui_post pp where pp.id=a.order_ids) is not null and tb_name='paotui_post' and a.deletetime is null");
		Db::name('order_merge')->execute("update pt_order_merge a set deletetime=(select deletetime from pt_shopro_order pp where pp.id=a.order_ids) where (select deletetime from pt_shopro_order pp where pp.id=a.order_ids) is not null and tb_name='shopro_order' and a.deletetime is null");
		return 'ok!';
	}
}
